<?php
namespace app\admin\controller;
use \think\Controller;
use think\Db;
use \Page;
use think\Request; 
class Statisticalquery extends CommController{
    //统计查询
    public function pro_query(){
     // /  $this->assign('idd',123);
      $data=db('user')->select();
     var_dump($data);
     $this->assign('list',$data);
        return $this->fetch('Statistical_query/pro_query');
    }
    public function score_query()
    {
      $data=db('user')->select();
     // var_dump($data);
     $this->assign('list',$data);
      return $this->fetch('Statistical_query/score_query');
    }
    public function score_select_dept()
    {
      $a=Request::instance();
      $dept=$a->post('dept');
      $grade=$a->post('grade');
      // var_dump($grade);
      if ($grade!=null) {
        $data=db('user')->where(['dept'=>$dept,'grade'=>$grade])->select();
      }
      else
      {
        $data=db('user')->where(['dept'=>$dept])->select();
      }

      return json_encode($data);
    }
    public function score_select_major()
    {
        $a=Request::instance();
        $dept=$a->post('dept');
        $major=$a->post('major');
        $grade=$a->post('grade');
        if ($grade!=null) {
          $data=db('user')->where(['dept'=>$dept,'major'=>$major,'grade'=>$grade])->select();
        }
        else
        {
          $data=db('user')->where(['dept'=>$dept,'major'=>$major])->select();
        }
        return json_encode($data);
    }
    public function score_select_grade(){
        $a=Request::instance();
        $dept=$a->post('dept');
        $major=$a->post('major');
        $grade=$a->post('grade');
        if ($dept==null&&$major==null)
        {
          $data=db('user')->where(['grade'=>$grade])->select();
          return json_encode($data);
        }
        else 
        {
          $data=db('user')->where(['dept'=>$dept,'major'=>$major,'grade'=>$grade])->select();
        }
        return json_encode($data);
    }
    public function score_class()
    {
      $a=Request::instance();
      $class=$a->post('class');
       $data=db('user')->where(['class'=>$class])->select();
       return json_encode($data);
    }
    public function select_stu_id()
    {
      $a=Request::instance();
      $stu_id=$a->post('stu_id');
       $data=db('user')->where(['stu_id'=>$stu_id])->select();
       return json_encode($data);
    }
    public function query()
    {
        $id=input('id');//学号
        $name=input('name');//姓名
        $pro_name=input('pro_name');//项目名称
        $class=input('class');//班级
        // $count=Db::table(user,)
        //  $data= Db::field('name,stu_id')
        // ->table('score_manage')
        // ->where('stu_id',$id)
        // ->union('SELECT name,stu_id FROM project_manage where stu_id='.$id.' ',true)
        // ->select();
        $data= Db::table('score_manage')
              ->alias('a')
              ->where('a.stu_id',$id)
              ->join('project_manage b','a.stu_id = b.stu_id')
              ->field(['a.*','b.name as agentname'])
              ->select();
        // var_dump($data);
    }

    public function pro_data()
    {
        $data=Db::query('select stu_id from user');
      //   foreach ($data as $key => $value) {
      //     if (is_string($data[$key])) {
      //      $data[$key] = urlencode ( $value );  
      //     }
            
      // }
        $data1=json_encode($data);
        // $data=urlencode($data1);
        $datas=array('code'=>0,
                'msg'=>'',
                'count'=>1000,
                'data'=>$data
              );
        foreach ($datas as $key => $value) {
          if (is_string($datas[$key])) {
           $datas[$key] = urlencode ( $value );  
          }
            
      }
        // $data2=json_encode($datas);
        // var_dump($data2);
        return  (json_encode($datas));
    }
}